import React from 'react';
import { connect } from 'dva';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Button, message } from 'antd';
import { SppIResultC, FirstHeaderC, SecuritiesCodeC } from '../../../comps';
@Form.create()
class SppIResult extends React.Component {
  constructor() {
    super();
    this.state = {
      SecuritiesCode: undefined,
      SecuritiesCode1: undefined,
      control: true,
      SPPI_result: undefined,
    };
  }

  securitiesCodeChange = (value) => {
    this.setState(
      {
        SecuritiesCode: value,
      },
      () => {
        this.getSPPI_Result();
      },
    );
  };
  //获取sppi结果
  getSPPI_Result = () => {
    const { SecuritiesCode } = this.state;
    // type   1-指令新增   2-簿记新增    3-簿记详情
    if (!SecuritiesCode) {
      this.setState(
        {
          SPPI_result: undefined,
        },
        () => {
          this.props.form.setFieldsValue({
            SPPI_result: this.state.SPPI_result,
          });
        },
      );
      return;
    }
    this.props.dispatch({
      type: 'bondTradeM/getSPPIResult',
      payload: {
        exchangeCode: SecuritiesCode.exchangeCode,
        tradingCode: SecuritiesCode.tradingCode,
      },
      callback: (data) => {
        let temp;
        if (data) {
          //sppi有值 不可点击新增按钮  无值可以
          temp = data.rgpd;
        } else {
          temp = undefined;
        }
        this.setState(
          {
            SPPI_result: temp,
          },
          () => {
            this.props.form.setFieldsValue({
              SPPI_result: this.state.SPPI_result,
            });
          },
        );
      },
    });
  };

  render() {
    const { SecuritiesCode, SecuritiesCode1, control, SPPI_result } = this.state;
    return (
      <>
        {/* 
              这里面也分为几种情况
              1.新增薄记或者新增指令,都是先选择证券代码后,然后才可以选择sppi结果
              2.详情得情况
            */}
        <FirstHeaderC title='薄记下达或者指令下达的时候,以非标为例'></FirstHeaderC>
        <SecuritiesCodeC
          form={this.props.form}
          onChange={(e) => {
            this.securitiesCodeChange(e);
          }}
          codeType={'nonstandard'} //非标举例子
        ></SecuritiesCodeC>

        <SppIResultC
          onRef={(ref) => (this.refs = ref)}
          selectProps={{
            SecuritiesCode: SecuritiesCode,
            rightContentShow: control, //右侧按钮是否展示，后面展示后的禁用逻辑，展示逻辑，组件控制
            SPPI_result: SPPI_result, //根据证券代码切换获取SPPI结果
            SppItype: 3,
            sppITitle: '新增测试',
          }}
          onOk={this.getSPPI_Result}
          form={this.props.form}
          dataIndex='SPPI_result'
          title='SPPI结果'
        ></SppIResultC>

        <FirstHeaderC title='详情展示方式'></FirstHeaderC>
        <SppIResultC
          onRef={(ref) => (this.refss = ref)}
          selectProps={{
            SecuritiesCode1,
            rightContentShow: false, //右侧按钮是否展示，后面展示后的禁用逻辑，展示逻辑，组件控制
            SppItype: 3,
            sppITitle: '新增测试',
          }}
          initialValue='1'
          form={this.props.form}
          dataIndex='SPPI_result1'
          title='SPPI结果'
        ></SppIResultC>
      </>
    );
  }
}
export default connect(({ bondTradeM }) => ({ bondTradeM }))(SppIResult);
